package com.guass.nettyprotostuff.schedule;

import com.guass.nettyprotostuff.rpc.common.SessionManager;
import com.guass.nettyprotostuff.zookeeper.ZookeeperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author guass
 * @date 2022年07月27日 13:42
 */
@Component
@Slf4j
public class ZkScheduleTask {

    @Resource
    private ZookeeperService zookeeperService;

    @Scheduled(cron = "10/5 * * * * *") //测试用
    @Async("taskScheduler")
    public void updateZkTask(){
        int count = SessionManager.getInstance().getChannelCount();

        try {
//            log.info("guass upate zk task {}，{}",count,zookeeperService.getForPath());
            zookeeperService.updateCounter(count);
        }catch (Exception e){

        }
    }

    @Scheduled(cron = "10/1 * * * * *") //测试用
    public void test(){
//        log.info("guass aaa");
    }
}
